#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int Maxn=3005;
int n,m;
char s[Maxn][Maxn],a[Maxn][Maxn];
short res[Maxn][Maxn],res1[Maxn][Maxn];
short f[Maxn][Maxn],g[Maxn][Maxn],h[Maxn][Maxn],h1[Maxn][Maxn];
ll ans;
void solve(int lx,int rx,int ly,int ry){
	if(lx==rx||ly==ry)return;
	if(rx-lx>ry-ly){
		int mid=lx+rx>>1;
		solve(lx,mid,ly,ry);solve(mid+1,rx,ly,ry);
		for(int i=ly;i<=ry;i++){
			f[lx][i]=f[rx][i]=1;
			for(int j=lx+1;j<=mid;j++)f[j][i]=1+(s[j][i]==s[j-1][i]?f[j-1][i]:0);
			for(int j=rx-1;j>mid;j--) f[j][i]=1+(s[j][i]==s[j+1][i]?f[j+1][i]:0);
		}
		//1
		for(int j=lx;j<=rx;j++)g[j][ry]=ry;
		for(int i=ry-1;i>=ly;i--)
			for(int j=lx;j<=rx;j++)g[j][i]=(s[j][i]==s[j][i+1]?g[j][i+1]:i);
		for(int i=ly;i<=ry;i++){
			for(int j=mid+1;j<=mid+f[mid+1][i];j++)++h[i][g[j][i]];
			for(int j=ry-1;j>i;j--)h[i][j]+=h[i][j+1];
			for(int j=mid;j>=mid-f[mid][i]+1;j--)++h1[i][g[j][i]];
			for(int j=ry-1;j>i;j--)h1[i][j]+=h1[i][j+1];
		}
		for(int i=ly;i<=ry;i++){
			for(int j=i+1;j<=ry;j++){
				if(f[mid+1][i]<=f[mid+1][j])res[i][j]=h[i][j];
				if(f[mid][i]<=f[mid][j])res1[i][j]=h1[i][j];
				h[i][j]=h1[i][j]=0;
			}
		}
		//2
		for(int j=lx;j<=rx;j++)g[j][ly]=ly;
		for(int i=ly+1;i<=ry;i++)
			for(int j=lx;j<=rx;j++)g[j][i]=(s[j][i]==s[j][i-1]?g[j][i-1]:i);
		for(int i=ly;i<=ry;i++){
			for(int j=mid+1;j<=mid+f[mid+1][i];j++)++h[i][g[j][i]];
			for(int j=ly+1;j<i;j++)h[i][j]+=h[i][j-1];
			for(int j=mid;j>=mid-f[mid][i]+1;j--)++h1[i][g[j][i]];
			for(int j=ly+1;j<i;j++)h1[i][j]+=h1[i][j-1];
		}
		for(int i=ly;i<=ry;i++){
			for(int j=i+1;j<=ry;j++){
				if(f[mid+1][i]>f[mid+1][j])res[i][j]=h[j][i];
				if(f[mid][i]>f[mid][j])res1[i][j]=h1[j][i];
				if(s[mid+1][i]==s[mid][i])ans+=res[i][j]*res1[i][j];
				h[j][i]=h1[j][i]=0;
			}
		}
	}else{
		int mid=ly+ry>>1;
		solve(lx,rx,ly,mid);solve(lx,rx,mid+1,ry);
		swap(lx,ly);swap(rx,ry);
		
		
		for(int i=ly;i<=ry;i++){
			f[lx][i]=f[rx][i]=1;
			for(int j=lx+1;j<=mid;j++)f[j][i]=1+(a[j][i]==a[j-1][i]?f[j-1][i]:0);
			for(int j=rx-1;j>mid;j--) f[j][i]=1+(a[j][i]==a[j+1][i]?f[j+1][i]:0);
		}
		//1
		for(int j=lx;j<=rx;j++)g[j][ry]=ry;
		for(int i=ry-1;i>=ly;i--)
			for(int j=lx;j<=rx;j++)g[j][i]=(a[j][i]==a[j][i+1]?g[j][i]=g[j][i+1]:i);
		for(int i=ly;i<=ry;i++){
			for(int j=mid+1;j<=mid+f[mid+1][i];j++)++h[i][g[j][i]];
			for(int j=ry-1;j>i;j--)h[i][j]+=h[i][j+1];
			for(int j=mid;j>=mid-f[mid][i]+1;j--)++h1[i][g[j][i]];
			for(int j=ry-1;j>i;j--)h1[i][j]+=h1[i][j+1];
		}
		for(int i=ly;i<=ry;i++)
			for(int j=i+1;j<=ry;j++){
				if(f[mid+1][i]<=f[mid+1][j])res[i][j]=h[i][j];
				if(f[mid][i]<=f[mid][j])res1[i][j]=h1[i][j];
				h[i][j]=h1[i][j]=0;
			}
		//2
		for(int j=lx;j<=rx;j++)g[j][ly]=ly;
		for(int i=ly+1;i<=ry;i++)
			for(int j=lx;j<=rx;j++)g[j][i]=(a[j][i]==a[j][i-1]?g[j][i]=g[j][i-1]:i);
		for(int i=ly;i<=ry;i++){
			for(int j=mid+1;j<=mid+f[mid+1][i];j++)++h[i][g[j][i]];
			for(int j=ly+1;j<i;j++)h[i][j]+=h[i][j-1];
			for(int j=mid;j>=mid-f[mid][i]+1;j--)++h1[i][g[j][i]];
			for(int j=ly+1;j<i;j++)h1[i][j]+=h1[i][j-1];
		}
		for(int i=ly;i<=ry;i++)
			for(int j=i+1;j<=ry;j++){
				if(f[mid+1][i]>f[mid+1][j])res[i][j]=h[j][i];
				if(f[mid][i]>f[mid][j])res1[i][j]=h1[j][i];
				if(a[mid+1][i]==a[mid][i])ans+=1ll*res[i][j]*res1[i][j];
				h[j][i]=h1[j][i]=0;
			}
	}
}

signed main(){
	freopen("star.in","r",stdin);
	freopen("star.out","w",stdout);
	n=read();m=read();
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)a[j][i]=s[i][j];
	solve(1,n,1,m);
	
	printf("%lld\n",ans);
	
	return 0;
}
/*
3 4
aaaa
aaba
aaaa
*/
